//
//  EWImageCommonCell.m
//  haveSomethingToEat
//
//  Created by 陈 宁权 on 17/4/11.
//  Copyright © 2017年 陈 宁权. All rights reserved.
//

#import "EWImageCommonCell.h"

@interface EWImageCommonCell()
@property (nonatomic,strong) UILabel *headingsLabel;
@property (nonatomic,strong) UIImageView *subHeadingsImageV;
@end

@implementation EWImageCommonCell

+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *identifier = @"EWCommonCell";
    // 1.缓存中取
    EWImageCommonCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    // 2.创建
    if (cell == nil) {
        cell = [[EWImageCommonCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupChildViews];
    }
    return self;
}

- (void)setupChildViews
{
    //主标题
    _headingsLabel = [[UILabel alloc] init];
    _headingsLabel.textAlignment = NSTextAlignmentLeft;
    _headingsLabel.font = [UIFont systemFontOfSize:15];
    [self.contentView addSubview:_headingsLabel];
    
    //副标题
    _subHeadingsImageV = [[UIImageView alloc] init];
    _subHeadingsImageV.layer.cornerRadius = 17;
    _subHeadingsImageV.layer.masksToBounds = YES;
    [self.contentView addSubview:_subHeadingsImageV];
    
    [_headingsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self);
        make.left.equalTo(self).offset(20);
        make.bottom.equalTo(self);
        make.width.offset(150);
    }];
    
    [_subHeadingsImageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(5);
        make.right.equalTo(self).offset(-30);
        make.width.offset(34);
        make.height.offset(34);
    }];
}

- (void)setHeadingsText:(NSString *)headingsText
{
    _headingsText = headingsText;
    _headingsLabel.text = _headingsText;
}

- (void)setSubHeadingsImageUri:(NSString *)subHeadingsImageUri
{
    [_subHeadingsImageV sd_setImageWithURL:[NSURL URLWithString:subHeadingsImageUri] placeholderImage:[UIImage imageNamed:@"publicNumber"]];
}

@end
